package components.navigation
{
	import com.degrafa.GeometryGroup;
	import com.degrafa.Surface;
	import com.degrafa.geometry.RoundedRectangleComplex;
	import com.degrafa.paint.SolidFill;
	
	import components.navigation.degree.DegreeTab;
	
	import controls.events.ServiceEvent;
	
	import mx.controls.ButtonLabelPlacement;
	import mx.controls.tabBarClasses.Tab;

	public class ProgressTab extends Tab
	{
		
		public function ProgressTab()
		{
			super();
			this.labelPlacement = ButtonLabelPlacement.TOP;
		}
		
		private var _data:Object;
		override public function set data(value:Object):void
		{
			_data = value;
		}
		override public function get data():Object
		{
			return _data;
		}
		
		private var percent:Number = 0;
		
		public var swatch:GeometryGroup;
		
		override protected function createChildren():void
		{
			super.createChildren();
			
			swatch = new GeometryGroup();
			
			var outline:RoundedRectangleComplex = new RoundedRectangleComplex(0, 0, 1, 1, 0, 0, 0, 0);
			swatch.geometryCollection.addItem(outline);
			
			var background:RoundedRectangleComplex = new RoundedRectangleComplex(0, 0, 1, 1, 0, 0, 0, 0);
			swatch.geometryCollection.addItem(background);
			
			var progressBar:RoundedRectangleComplex = new RoundedRectangleComplex(0, 0, 1, 1, 0, 0, 0, 0);
			swatch.geometryCollection.addItem(progressBar);
			
			var surface:Surface = new Surface();
			swatch.target = surface;
			this.addChild(surface);
		}
		
		override protected function commitProperties():void
		{
			super.commitProperties();
			
			if(_data != null)
				percent = _data as Number;
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			
			var outline:RoundedRectangleComplex = swatch.geometryCollection.items[0] as RoundedRectangleComplex;
			outline.width = unscaledWidth - 10;
			outline.height = unscaledHeight/3 - 4;
			outline.fill = new SolidFill(0x000000, 1);
			outline.x = 5;
			outline.y = unscaledHeight - unscaledHeight/3;
			
			var background:RoundedRectangleComplex = swatch.geometryCollection.items[1] as RoundedRectangleComplex;
			background.width = unscaledWidth - 12;
			background.height = outline.height - 2;
			background.fill = new SolidFill(0xCCCCCC, 1);
			background.x = 6;
			background.y = outline.y + 1;
			
			var progressBar:RoundedRectangleComplex = swatch.geometryCollection.items[2] as RoundedRectangleComplex;
			progressBar.width = background.width * percent;
			progressBar.height = outline.height - 2;
			progressBar.fill = new SolidFill(DegreeTab.TAKEN, 1);
			progressBar.x = 6;
			progressBar.y = outline.y + 1;
		}
	}
}